package offer;

import java.io.File;
import java.sql.Date;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.ServletRequestAware;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;
import com.oreilly.servlet.MultipartRequest;
import com.oreilly.servlet.multipart.DefaultFileRenamePolicy;



public class BoardAddAction extends ActionSupport{
	//HttpServletRequest request;
	BoardBean boarddata;
	
	private File board_file;//업로드할 실제 파일
	private String board_fileFileName;//업로드할 로컬 파일이름
	private String board_fileContentType;//업로드할 파일의 컨텐츠 타입
	private String serverFullPath;//저장할 실제 파일의 전체 경로

	
	 public String execute() throws Exception{
		System.out.println("업로드된 파일이름: "+board_fileFileName);
		
		System.out.println("BoardBean의 writer변수값: "+boarddata.getWriter());
		 
		BoardDAO boarddao=new BoardDAO();
		String saveFolder="/boardupload";
		//String realFolder=request.getRealPath(saveFolder);
		File realFolder = new File(saveFolder);
		String realPath = realFolder.getParent();
		
		FileService fileService = new FileService();
		File uploadFile = fileService.saveFile(board_file, realPath, board_fileFileName);
		serverFullPath = uploadFile.getPath();
		System.out.println("FileService클래스 처리된 업로드된 파일: "+uploadFile.getName());
		
		
		boarddata.setBoard_file(serverFullPath);
	   		
	   		boolean result=boarddao.boardInsert(boarddata);
	   		
	   		if(result==false){
	   			System.out.println("안됨");
	   		}
	   		System.out.println("됨");
	   		
	   
  		return SUCCESS;
	}



	public File getBoard_file() {
		return board_file;
	}





	public void setBoard_file(File board_file) {
		this.board_file = board_file;
	}





	public String getBoard_fileFileName() {
		return board_fileFileName;
	}





	public void setBoard_fileFileName(String board_fileFileName) {
		this.board_fileFileName = board_fileFileName;
	}





	public String getBoard_fileContentType() {
		return board_fileContentType;
	}





	public void setBoard_fileContentType(String boardFileContentType) {
		this.board_fileContentType = boardFileContentType;
	}


	public BoardBean getBoarddata() {
		return boarddata;
	}


	public void setBoarddata(BoardBean boarddata) {
		this.boarddata = boarddata;
	}


	public String getServerFullPath() {
		return serverFullPath;
	}


	public void setServerFullPath(String serverFullPath) {
		this.serverFullPath = serverFullPath;
	}

}